package com.qinggeng.project.system.service.impl;

import com.qinggeng.common.utils.DateUtils;
import com.qinggeng.project.api.security.utils.ApiUtils;
import com.qinggeng.project.system.domain.CostFree;
import com.qinggeng.project.system.mapper.CostFreeMapper;
import com.qinggeng.project.system.service.ICostFreeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service
public class CostFreeServiceImpl implements ICostFreeService {

    @Resource
    private CostFreeMapper costFreeMapper;

    @Override
    public int insertCostFree(CostFree costFree) {
        return costFreeMapper.insertCostFree(costFree);
    }

    @Override
    public int updateCostFree(CostFree costFree) {
        return costFreeMapper.updateCostFree(costFree);
    }

    @Override
    public int updateCostFreeRecord(Long userId){
        CostFree costFree = selectCostFreeByUserId(userId);
        if(costFree==null){
            costFree=new CostFree(userId, 1, DateUtils.getDate());
            return insertCostFree(costFree);
        }
        return updateCostFreeCount(costFree);
    }


    @Override
    public CostFree selectCostFreeByUserId(Long userId) {
        return costFreeMapper.selectCostFreeByUserId(userId, DateUtils.getDate());
    }

    @Override
    public int updateCostFreeCount(CostFree costFree) {
        return costFreeMapper.updateCostFreeCount(costFree);
    }
}
